<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2018/6/25
  Time: 15:24
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" import="java.lang.*" %>
<%@ page import="java.util.Enumeration" %>
<html>
<head>
    <title>Title</title>
</head>
<body>
<a href="gotoLogin.do"> 跳转到登录页面</a>
<%!
    String name1 = "张三";
    String name2 = "李四";

    int add(int a, int b) {
        return a + b;
    }
%>
<h1>你好  <%=name1%>
</h1>  <br>
<h1>你好 ${name2}</h1>  <br>
3+5=<%= add(3, 5)%>
<h1>内置对象_out</h1>
<%
    out.println("<h2>静夜思</h2>");//可以在println();里面加入标签
    out.println("床前明月光");
    out.println("疑是地上霜");
    out.flush();
    // out.clear();//这里会抛出异常，因为上面有flush
    out.clearBuffer();//这里不会抛出异常
    out.println("举头望明月");
    out.println("低头思故乡");
%>
缓冲区大小：<%=out.getBufferSize() %>byte<br>
缓冲区剩余大小：<%=out.getRemaining() %>byte<br>
是否自动清空缓冲区：<%=out.isAutoFlush() %><br>

<h1>内置对象_request</h1>
<form action="testPost.do" method="post">
    用户名<input type="text" name="userName"> <br>
    密码<input type="text" name="passWord"><br>
    爱好
    听音乐 <input type="checkbox" name="hobby" value="听音乐">
    看电影 <input type="checkbox" name="hobby" value="看电影">
    读书 <input type="checkbox" name="hobby" value="读书">
    打游戏 <input type="checkbox" name="hobby" value="打游戏">
    <br>
    <input type="submit" value="提交">
</form>

<%
    response.setContentType("text/html;chatset=utf-8");
    out.println("<h1>内置对象_response</h1>");
    out.println("<br>");
%>
<br>
<h1>session内置对象</h1>
<%
    session.setAttribute("userName", "admin");
%>
<%=session.getCreationTime()%>
<%=session.getAttribute("userName")%>
<h1>application 对象</h1>

<%
    application.setAttribute("国家", "中国");
    application.setAttribute("省", "河北省");
    application.setAttribute("市", "北京市");
%>
所在城市独立版:<%= application.getAttribute("国家")%> <%=application.getAttribute("省")%> <%=application.getAttribute("市")%>
<br>
所在城市集合版:
<%
    Enumeration<String> attributeNames = application.getAttributeNames();
    while (attributeNames.hasMoreElements()) {
        out.println(attributeNames.nextElement() + " ");
    }
%>
<h1>page内置对象</h1>
<%
   String p =  page.toString();
   out.print(p);
%>
<h1>pageContext内置对象</h1>
session中的用户名:<%= pageContext.getSession().getAttribute("userName")%>
</body>
</html>
